function MontandoConfiguracion()
{
    $("#divConf").show();
}

function CreaConfiguracion()
{
    DivExtra();
    DatosDBA();
    DatosLogin();
    HoraCorte();
    MarcasPorcentuales();
    CheckBoxes();
    CreaBt();
    ImagenConf();
    
    LeeConfiguracion();
}
function DatosDBA()
{

    var formDatosDBA = document.createElement("form");
    formDatosDBA.setAttribute("id", "formDatosDBA");

    var fieldsetDatosDba = document.createElement("fieldset");
    fieldsetDatosDba.setAttribute("id", "fieldsetDatosDba");
    fieldsetDatosDba.setAttribute("class", "fieldset1");

    var leyendFiledba = document.createElement("legend");
    leyendFiledba.setAttribute("id", "leyendFiledba");
    leyendFiledba.innerHTML = "Datos DBA";



    var divLabelsConf = document.createElement("div");
    divLabelsConf.setAttribute("id", "divLabelsConf");
    divLabelsConf.setAttribute("class", "divLabels");


    var divTextsConf = document.createElement("div");
    divTextsConf.setAttribute("id", "divTextsConf");
    divTextsConf.setAttribute("class", "divTexts");


    var labelNameDBA = document.createElement("label");
    labelNameDBA.setAttribute("id", "labelNameDBA");
    labelNameDBA.setAttribute("class", "label labelConf");
    labelNameDBA.innerHTML = "NOMBRE DBA:";

    var textNameDBA = document.createElement("input");
    textNameDBA.setAttribute("type", "input");
    textNameDBA.setAttribute("size", "40");
    textNameDBA.setAttribute("id", "textNameDBA");
    //textNameDBA.setAttribute("value", "Juan Jose Salazar");
    textNameDBA.setAttribute("class", "campoTexto textConf");

    divLabelsConf.appendChild(labelNameDBA);
    divTextsConf.appendChild(textNameDBA);

    var labelMailDBA = document.createElement("label");
    labelMailDBA.setAttribute("id", "labelMailDBA");
    labelMailDBA.setAttribute("class", "label labelConf");
    labelMailDBA.innerHTML = "Correo Electronico DBA:";

    var textMailDBA = document.createElement("input");
    textMailDBA.setAttribute("type", "email");
    textMailDBA.setAttribute("size", "40");
    textMailDBA.setAttribute("id", "textMailDBA");
    //textMailDBA.setAttribute("value", "textMailDBA");
    textMailDBA.setAttribute("class", "campoTexto textConf");

    divLabelsConf.appendChild(labelMailDBA);
    divTextsConf.appendChild(textMailDBA);

    fieldsetDatosDba.appendChild(leyendFiledba);
    fieldsetDatosDba.appendChild(divLabelsConf);
    fieldsetDatosDba.appendChild(divTextsConf);



    formDatosDBA.appendChild(fieldsetDatosDba);

    document.getElementById("divConf1").appendChild(formDatosDBA);
    
}


function DatosLogin()
{

    var formLogin = document.createElement("form");
    formLogin.setAttribute("id", "formLogin");

    var fieldsetLogin = document.createElement("fieldset");
    fieldsetLogin.setAttribute("id", "fieldsetLogin");
    fieldsetLogin.setAttribute("class", "fieldset1");

    var leyendLogin = document.createElement("legend");
    leyendLogin.setAttribute("id", "leyendLogin");
    leyendLogin.innerHTML = "Datos del Login";

    var DivLogin = document.createElement("div");
    DivLogin.setAttribute("id", "DivLogin");
    DivLogin.setAttribute("class", "DivConfDerecha");


    var labelUser = document.createElement("label");
    labelUser.setAttribute("id", "labelUser");
    labelUser.setAttribute("class", "label labelLogin");
    labelUser.innerHTML = "Nombre Usuario:";

    var textUser = document.createElement("input");
    textUser.setAttribute("type", "input");
    textUser.setAttribute("size", "40");
    textUser.setAttribute("id", "textUser");
    textUser.setAttribute("readonly", "readonly");
    //textUser.setAttribute("value", "SYS");
    textUser.setAttribute("class", "campoTexto textLogin");



    var divUser = document.createElement("div");
    divUser.setAttribute("id", "divUser");
    divUser.setAttribute("class", "divsLogins");


    divUser.appendChild(labelUser);
    divUser.appendChild(textUser);

    var labelcontrasena = document.createElement("label");
    labelcontrasena.setAttribute("id", "labelcontrasena");
    labelcontrasena.setAttribute("class", "label labelLogin");
    labelcontrasena.innerHTML = "Contraseña:";

    var textContrasena = document.createElement("input");
    textContrasena.setAttribute("type", "password");
    textContrasena.setAttribute("size", "40");
    textContrasena.setAttribute("id", "textContrasena");
    // textContrasena.setAttribute("value", "root");
    textContrasena.setAttribute("class", "campoTexto textLogin");

    var divContasena = document.createElement("div");
    divContasena.setAttribute("id", "divContasena");
    divContasena.setAttribute("class", "divsLogins");

    divContasena.appendChild(labelcontrasena);
    divContasena.appendChild(textContrasena);

    var labelCheck = document.createElement("label");
    labelCheck.setAttribute("id", "labelCheck");
    labelCheck.setAttribute("class", "label labelLogin");
    labelCheck.innerHTML = "Recordarme";

    var checkLogin = document.createElement("input");
    checkLogin.setAttribute("type", "checkbox");
    checkLogin.setAttribute("checked", "true");
    checkLogin.setAttribute("id", "checkLogin");

    var divCheck = document.createElement("div");
    divCheck.setAttribute("id", "divCheck");
    divCheck.setAttribute("class", "divsLogins");


    divCheck.appendChild(labelCheck);
    divCheck.appendChild(checkLogin);

    DivLogin.appendChild(divUser);
    DivLogin.appendChild(divContasena);
    DivLogin.appendChild(divCheck);


    fieldsetLogin.appendChild(DivLogin);

    fieldsetLogin.appendChild(leyendLogin);

    formLogin.appendChild(fieldsetLogin);

    document.getElementById("divConf1").appendChild(formLogin);

}


function HoraCorte()
{


    var formHora = document.createElement("form");
    formHora.setAttribute("id", "formHora");

    var fieldsetHora = document.createElement("fieldset");
    fieldsetHora.setAttribute("id", "fieldsetHora");
    fieldsetHora.setAttribute("class", "fieldset1");

    var leyendHora = document.createElement("legend");
    leyendHora.setAttribute("id", "leyendHora");
    leyendHora.innerHTML = "Hora de Corte";

    fieldsetHora.appendChild(leyendHora);

    var labelHora = document.createElement("label");
    labelHora.setAttribute("id", "labelHora");
    labelHora.setAttribute("class", "label labelHora");
    labelHora.innerHTML = "Hora de corte: ";

    var textHora = document.createElement("input");
    textHora.setAttribute("type", "time");
    //textHora.setAttribute("value", "00:00:00");
    textHora.setAttribute("id", "textHora");

    var divHora = document.createElement("div");
    divHora.setAttribute("id", "divHora");

    divHora.appendChild(labelHora);
    divHora.appendChild(textHora);

    fieldsetHora.appendChild(divHora);

    formHora.appendChild(fieldsetHora);

    document.getElementById("divConf2").appendChild(formHora);

}

function MarcasPorcentuales()
{
    var formMarcas = document.createElement("form");
    formMarcas.setAttribute("id", "formMarcas");

    var fieldsetMarca = document.createElement("fieldset");
    fieldsetMarca.setAttribute("id", "fieldsetMarca");
    fieldsetMarca.setAttribute("class", "fieldset1");

    var leyendMarca = document.createElement("legend");
    leyendMarca.setAttribute("id", "leyendMarca");
    leyendMarca.innerHTML = "Marcas de Alerta";

    fieldsetMarca.appendChild(leyendMarca);


    var labelMarca1 = document.createElement("label");
    labelMarca1.setAttribute("id", "labelMarca1");
    labelMarca1.setAttribute("class", "label labelMarca");
    labelMarca1.innerHTML = "Primera Marca : ";

    var textMarca1 = document.createElement("input");
    textMarca1.setAttribute("type", "number");
    //textMarca1.setAttribute("value", "75");
    textMarca1.setAttribute("min", "0");
    textMarca1.setAttribute("max", "100");
    textMarca1.setAttribute("id", "textMarca1");

    var divMarca1 = document.createElement("div");
    divMarca1.setAttribute("id", "divMarca1");

    divMarca1.appendChild(labelMarca1);
    divMarca1.appendChild(textMarca1);

    var labelMarca2 = document.createElement("label");
    labelMarca2.setAttribute("id", "labelMarca2");
    labelMarca2.setAttribute("class", "label labelMarca");
    labelMarca2.innerHTML = "Segunda Marca : ";

    var textMarca2 = document.createElement("input");
    textMarca2.setAttribute("type", "number");
    // textMarca2.setAttribute("value", "90");
    textMarca2.setAttribute("min", "0");
    textMarca2.setAttribute("max", "100");
    textMarca2.setAttribute("id", "textMarca2");

    var divMarca2 = document.createElement("div");
    divMarca2.setAttribute("id", "divMarca2");

    divMarca2.appendChild(labelMarca2);
    divMarca2.appendChild(textMarca2);


    fieldsetMarca.appendChild(divMarca1);
    fieldsetMarca.appendChild(divMarca2);


    formMarcas.appendChild(fieldsetMarca);

    document.getElementById("divConf2").appendChild(formMarcas);
}

function CreaBt()
{
    var botguardar = document.createElement("input");
    botguardar.type = "submit";
    botguardar.value = "Guardar";
    botguardar.setAttribute("class", "botL");
    botguardar.setAttribute("tabindex", "3");
    botguardar.setAttribute("onclick", "GuardaConfiguracion()");
    botguardar.id = "botguardar";
    
    document.getElementById("divConf2").appendChild(botguardar);
}

function DivExtra()
{
    var divConf1 = document.createElement("div");
    divConf1.setAttribute("id", "divConf1");
    divConf1.setAttribute("class", "divExtra");

    var divConf2 = document.createElement("div");
    divConf2.setAttribute("id", "divConf2");
    divConf2.setAttribute("class", "divExtra");

    document.getElementById("divConf").appendChild(divConf1);
    document.getElementById("divConf").appendChild(divConf2);
}

function ImagenConf()
{
    var divImgConf = document.createElement("div");
    divImgConf.setAttribute("id", "divImgConf");

    var ImgConf = document.createElement("img");
    ImgConf.setAttribute("id", "ImgConf");
    ImgConf.setAttribute("src", "Images/conf2.png");
    ImgConf.setAttribute("alt", "IMAGEN CONFIGURACION ");

    divImgConf.appendChild(ImgConf);

    document.getElementById("divConf2").appendChild(divImgConf);
}


function CheckBoxes()
{
    var divBoxesConf = document.createElement("div");
    divBoxesConf.setAttribute("id", "divBoxesConf");
    
    var labelExtender = document.createElement("label");
    labelExtender.setAttribute("id", "labelExtender");
    labelExtender.setAttribute("class", "label labelMarca");
    labelExtender.innerHTML = "Extender Tablespace  ";
    
    var checkExt = document.createElement("input");
    checkExt.setAttribute("type", "checkbox");
    //checkExt.setAttribute("checked", "false");
    checkExt.setAttribute("id", "checkExt");
    checkExt.setAttribute("onclick", "checkext()");
    
   
    divBoxesConf.appendChild(labelExtender);
    divBoxesConf.appendChild(checkExt);
    
    
    var labelCreaDF = document.createElement("label");
    labelCreaDF.setAttribute("id", "labelCreaDF");
    labelCreaDF.setAttribute("class", "label labelMarca");
    labelCreaDF.innerHTML = "Crear Datafile";
    
    var checkDT = document.createElement("input");
    checkDT.setAttribute("type", "checkbox");
    //checkDT.setAttribute("checked", "false");
    checkDT.setAttribute("id", "checkDT");
    checkDT.setAttribute("onclick", "checkAddDT()");
        
    divBoxesConf.appendChild(labelCreaDF);
    divBoxesConf.appendChild(checkDT);
    
    checkext();

    document.getElementById("divConf2").appendChild(divBoxesConf);
}

function GuardaConfiguracion()
{

    var arrayConf = new Array();

    //datos dba
    arrayConf.push(document.getElementById("textNameDBA").value);
    arrayConf.push(document.getElementById("textMailDBA").value);
    //datos login
    arrayConf.push(document.getElementById("textUser").value);//textUser
    arrayConf.push(document.getElementById("textContrasena").value);//textContrasena
    arrayConf.push(document.getElementById("checkLogin").checked);//checkLogin
    //hora corte
    arrayConf.push(document.getElementById("textHora").value);//textHora
    //Marcas
    arrayConf.push(document.getElementById("textMarca1").value);//textMarca1
    arrayConf.push(document.getElementById("textMarca2").value);//textMarca2


    $.ajax
            ({
                type: "POST",
                url: "./CallProcedure1.php",
                data:
                        {
                            req: "Configurando",
                            arrayConf: JSON.stringify(arrayConf)

                        }

            });
}

function checkext()
{
    alert("checkext");
       
    jQuery('#checkExt').attr('checked','checked'); //pongo en check
    jQuery('#checkDT').removeAttr('checked');//quito el check
    
}
function checkAddDT()
{
    alert("checkAddDT");
  
    jQuery('#checkDT').attr('checked','checked');//quito el check
     jQuery('#checkExt').removeAttr('checked'); //pongo en check
 }

function LeeConfiguracion()
{

    $.ajax
            ({
                type: "POST",
                url: "./CallProcedure1.php",
                data:
                        {
                            req: "Configurando2"

                        },
                success: function(data)
                {
                    //                alert(data);
                    var json = jQuery.parseJSON(data);
                    if (json.success)
                    {
                        //datos dba
                        document.getElementById("textNameDBA").value = json.Elements[0][0];
                        document.getElementById("textMailDBA").value = json.Elements[0][1];
                        //datos login
                        document.getElementById("textUser").value = json.Elements[0][2];//textUser
                        document.getElementById("textContrasena").value = json.Elements[0][3];//textContrasena

                        //validar el check
                        if (json.Elements[0][4] == "true")
                            document.getElementById("checkLogin").checked = true;//checkLogin
                        else
                            document.getElementById("checkLogin").checked = false;//checkLogin
                        //hora corte
                        document.getElementById("textHora").value = json.Elements[0][5];//textHora
                        //Marcas
                        document.getElementById("textMarca1").value = json.Elements[0][6];//textMarca1
                        document.getElementById("textMarca2").value = json.Elements[0][7];//textMarca2

                        //   alert(json.success);
                    }

                }

            });



}


function RedimnesionarTablespace(tablespace)
{
    alert("redimensionando Tablespace");

    //createWaiting();
    $.ajax
            ({
                type: "POST",
                url: "./ManejoTablespace.php",
                data:
                        {
                            req: "Redimensionando",
                            tablespace: tablespace
                        },
                success: function(data)
                {
                    alert("entro ");
                    alert(data);

                    var json = jQuery.parseJSON(data);
                    alert(json.success);


                    if (json.success)
                    {
                        alert("Redimensionando con exito");
                    }
                }
            });
}
function CrearDatafile(tablespace)
{
    //createWaiting();
    $.ajax
            ({
                type: "POST",
                url: "./ManejoTablespace.php",
                data:
                        {
                            req: "CreandoDatafile",
                            tablespace: tablespace
                        },
                success: function(data)
                {
                    alert(data);

                    var json = jQuery.parseJSON(data);
                    alert(json.success);
                }
            });
}

